package com.ruoyi.basicsystem.controller;

import com.ruoyi.common.utils.SecurityUtils;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basicsystem.domain.ZnPerson;
import com.ruoyi.basicsystem.service.IZnPersonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 经手人Controller
 * 
 * @author ruoyi
 * @date 2022-03-04
 */
@RestController
@RequestMapping("/basicsystem/person")
public class ZnPersonController extends BaseController
{
    @Autowired
    private IZnPersonService znPersonService;

    /**
     * 查询经手人列表
     */
    @PreAuthorize("@ss.hasAnyPermi('basicsystem:person:list,bill:saleorder:add')")
    @GetMapping("/list")
    public TableDataInfo list(ZnPerson znPerson)
    {
        startPage();
        List<ZnPerson> list = znPersonService.selectZnPersonList(znPerson);
        return getDataTable(list);
    }

    /**
     * 导出经手人列表
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:person:export')")
    @Log(title = "经手人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZnPerson znPerson)
    {
        znPerson.setTenantId(SecurityUtils.getTenantId());
        List<ZnPerson> list = znPersonService.selectZnPersonList(znPerson);
        ExcelUtil<ZnPerson> util = new ExcelUtil<ZnPerson>(ZnPerson.class);
        util.exportExcel(response, list, "经手人数据");
    }

    /**
     * 获取经手人详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:person:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(znPersonService.selectZnPersonById(id));
    }

    /**
     * 新增经手人
     */
//    @PreAuthorize("@ss.hasPermi('basicsystem:person:add')")
    @Log(title = "经手人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZnPerson znPerson)
    {
        return toAjax(znPersonService.insertZnPerson(znPerson));
    }

    /**
     * 修改经手人
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:person:edit')")
    @Log(title = "经手人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZnPerson znPerson)
    {
        return toAjax(znPersonService.updateZnPerson(znPerson));
    }

    /**
     * 删除经手人
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:person:remove')")
    @Log(title = "经手人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(znPersonService.deleteZnPersonByIds(ids));
    }

    /**
     * 查询经手人列表
     */
    @GetMapping("/selectlist")
    public AjaxResult selectlist(ZnPerson znPerson)
    {
        List<ZnPerson> list = znPersonService.selectZnPersonList(znPerson);
        return AjaxResult.success(list);
    }
}
